 /*普通版本制作*/
 /*
 	列表
 		- 勾选商品
 		- 数量
 		- 小计
 	统计
 		- 全选
 		- 已勾选商品件数
 		- 总计商品件数
 		- 总额计算
 		- 现在结算的点击
 */
 var blueCheckboxes = document.querySelectorAll('.items-choose .blue-checkbox-new');
 var ups = document.querySelectorAll('.up');
 var downs = document.querySelectorAll('.down');
 var numInputs = document.querySelectorAll('.num input');
 var subtotals = document.querySelectorAll('.cart-top-items .subtotal');
 var prices = document.querySelectorAll('.cart-top-items .price');
 var chooseAll = document.querySelector('.choose-all .blue-checkbox-new');
 var totalNum = document.querySelector('.shipping-total h5 i');
 var checkedNum = document.querySelector('.shipping-total h4 i');
 var nowBuy = document.querySelector('.jianguo-blue-main-btn');
 var moneyall = document.querySelector('.moneyall');


 var alltrue = false;

 getTotalNum();

 for (let i = 0; i < blueCheckboxes.length; i++) {
     blueCheckboxes[i].isCheck = false;
     blueCheckboxes[i].onclick = function() {
         this.classList[this.isCheck ? 'remove' : 'add']('checkbox-on');
         this.isCheck = !this.isCheck;
         setAllChecked();
         setClass();
         getCheckNum();
     }
     ups[i].onclick = function() {
         let text = numInputs[i].value;
         text = Math.min(10, Number(text) + 1)
         text == 10 && this.classList.add('up-disabled');
         text > 1 && downs[i].classList.remove('down-disabled');
         numInputs[i].value = text;
         subtotals[i].innerHTML = '￥ ' + getPrice(prices[i].innerHTML, numInputs[i].value);
         getTotalNum();
         getCheckNum();
     }
     downs[i].onclick = function() {
         let text = numInputs[i].value;
         text = Math.max(1, Number(text) - 1);
         text == 1 && this.classList.add('down-disabled');
         text < 10 && ups[i].classList.remove('up-disabled');
         numInputs[i].value = text;
         subtotals[i].innerHTML = '￥ ' + getPrice(prices[i].innerHTML, numInputs[i].value);
         getTotalNum();
         getCheckNum();
     }
     subtotals[i].innerHTML = '￥ ' + getPrice(prices[i].innerHTML, numInputs[i].value);
     ups[i].classList[numInputs[i].value == 10 ? 'add' : 'remove']('up-disabled');
     downs[i].classList[numInputs[i].value == 1 ? 'add' : 'remove']('down-disabled');
     // getTotalNum();
 }
 //点击全选按钮
 chooseAll.onclick = function() {
         this.classList[alltrue ? 'remove' : 'add']('checkbox-on');
         blueCheckboxes.forEach(item => {
             item.classList[!alltrue ? 'add' : 'remove']('checkbox-on')
             item.isCheck = !alltrue;
         })
         alltrue = !alltrue;
         setClass();
         getCheckNum();
     }
     //处理小计
 function getPrice(str, num) {
     var pricemoney = 0;
     str = str.slice(1).trim();
     pricemoney = parseFloat(str) * num;
     return Number(pricemoney.toFixed(2));
 }

 //处理是否全选状态
 function setAllChecked() {
     var isAllChecked = [...blueCheckboxes].every(item => item.isCheck);
     alltrue = isAllChecked;
     chooseAll.classList[isAllChecked ? 'add' : 'remove']('checkbox-on');
 }
 //获取总计件数
 function getTotalNum() {
     var totalnum = 0;
     totalnum = [...numInputs].reduce((a, b) => {
         b = Number(b.value);
         //					var c = a+b;
         return a + b;
     }, 0)
     totalNum.innerHTML = totalnum;
 }
 //设置现在结算按钮
 function setClass() {
     var isAllChecked = [...blueCheckboxes].some(item => item.isCheck);
     nowBuy.classList[isAllChecked ? 'remove' : 'add']('disabled-btn');
 }
 //设置选中的商品件数和应付金额
 function getCheckNum() {
     var checknum = 0;
     var moneyA = 0;
     blueCheckboxes.forEach((item, index) => {
         if (item.isCheck) {
             checknum += Number(numInputs[index].value);
             moneyA += getPrice(prices[index].innerHTML, numInputs[index].value);
         }
     })
     checkedNum.innerHTML = checknum;
     moneyall.innerHTML = moneyA;
 }

 /**
     选中: checkbox-on
     结算按钮样式: disabled-btn
     加减按钮禁用：down-disabled
 */